<?
//connect to database . You have to defini the varialbes in file config.php
include("config.php");
function __autoload($nameLoad){
			require_once("models/$nameLoad.class.php");
}

include("models/conect.php");
//this file just analyse url to id (category or product)
//detect Id of category

if(isset($input_find_cat_or_id) and $input_find_cat_or_id!=''){
	 $sql="SELECT ".ID_CATEGORY." FROM ".TAB_CATEGORY." WHERE ".LINK_CATEGORY." = '$input_find_cat_or_id'";
	$query=$mysqli->query($sql);
	if($query->num_rows){
		$row=$query->fetch_assoc();
		$id_cat=$row[ID_CATEGORY];
	}
	
	//detect Id of Product (with Link in info)
	$sql="SELECT * FROM `product` WHERE prd_lien = '$input_find_cat_or_id'";
	$query=$mysqli->query($sql);
	if($query->num_rows){
		$row=$query->fetch_assoc();
		$id_prod_info=$row[ID_PRODUCT];
	}
	
	//detect Id of page contenu (with Link in info)
	$sql="SELECT `id` FROM `page_article` where `seoname` = '$input_find_cat_or_id'";
	$query=$mysqli->query($sql);
	if($query->num_rows){
		$row=$query->fetch_assoc();
		$id_page=$row['id'];
	}
}

//detect Id of Product (with Link in product)
if(isset($id_prod_info)){
	 $sql="SELECT product_id FROM product WHERE prd_id = '$id_prod_info'";
	$query=$mysqli->query($sql);
	if($query->num_rows){
		$row=$query->fetch_assoc();
		$product_id=$row["product_id"];
	}
}elseif(isset($input_find_cat_or_id) && $input_find_cat_or_id!=''){
	 $sql="SELECT product_id,prd_id FROM product WHERE prd_lien = '$input_find_cat_or_id'";
	$query=$mysqli->query($sql);
	if($query->num_rows){
		$row=$query->fetch_assoc();
		$id_prod_info=$row["prd_id"];
		$product_id=$row["product_id"];
	}
}
//take category for product
if(isset($product_id)){
	$cat_url=array_reverse($match);
	 $sql="SELECT ".ID_CATEGORY." FROM ".TAB_CATEGORY." WHERE ".LINK_CATEGORY." = '{$cat_url[1]}'";
	$query=$mysqli->query($sql);
	if($query->num_rows){
		$row=$query->fetch_assoc();
		$id_cat_product=$row[ID_CATEGORY];
	}
}